{include file="common/head"/}
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try{ace.settings.check('main-container' , 'fixed')}catch(e){}
    </script>
    {include file="common/left"}
    <div class="main-content">
        <div class="main-content-inner">
            {include file="common/header_nav"}
            <div class="page-content">
                <div class="row maintop">

                    <form class="form-horizontal" name="ruleAdd" id="ruleAdd" method="post" action="{:url('ruleAdd')}">
                        <div class="col-xs-12 col-sm-12">
                            <small>菜单状态：</small>
                            <small>
                                <select name="status">
                                    <option value="1">显示</option>
                                    <option value="0">不显示</option>
                                </select>
                            </small>
                            <small class="sl-left10">父级：</small>
                            <small>
                                <select name="pid">
                                    <option value="0">--默认顶级--</option>
                                    {foreach name="admin_rule" item="v"}
                                    <option value="{$v.id}" style="margin-left:55px;">
                                        {$v.lefthtml}{$v.title}
                                    </option>
                                    {/foreach}
                                </select>
                            </small>
                            <small class="sl-left10">名称：</small>
                            <small><input name="title" id="title" class="rule" placeholder=" 输入名称"/></small>
                            <small class="sl-left10">控/方：</small>
                            <small><input name="name" id="name" class="rule" placeholder=" 输入控制器/方法"/></small>
                            <small class="sl-left10">css：</small>
                            <small><input name="css" id="css" class="wh50" placeholder=" css样式"/></small>
                            <small class="sl-left10">排序：</small>
                            <small><input name="sort" id="sort" class="wh30" value="50"/></small>
                            <small>
                                <button class="btn btn-xs btn-danger ruleadd">添加权限</button>
                            </small>
                        </div>
                    </form>
                </div>
                <div class="col-xs-12 col-sm-12 rule-top alert alert-info top10">
                    <button type="button" class="close" data-dismiss="alert">
                        <i class="ace-icon fa fa-times"></i>
                    </button>
                    1、《控/方》：意思是 控制器/方法; 例如 Sys/sys_list<br/>
                    2、css为控制左侧导航顶级栏目前图标样式，具体可查看FontAwesome图标CSS样式
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <div class="row">
                            <div class="col-xs-12">
                                <form id="ruleorder" name="ruleorder" method="post" action="{:url('ruleorder')}">
                                <div class="table-responsive">
                                    <table id="simple-table" class="table table-striped table-bordered table-hover center">
                                        <thead>
                                        <tr>
                                            <th class="center">ID</th>
                                            <th class="text-left">权限名称</th>
                                            <th class="text-left visible-lg visible-md">控制器/方法</th>
                                            <th class="center">是否验证权限</th>
                                            <th class="center">栏目菜单状态</th>
                                            <th class="center visible-lg visible-md">排序</th>
                                            <th class="center" style="border-right:1px solid #ddd; ">操作</th>
                                        </tr>
                                        </thead>

                                        <tbody>
                                        {volist name="admin_rule" id="v"}
                                        <tr>
                                            <td>{$v.id}</td>
                                            <td class="text-left">{$v.lefthtml}{$v.title}</td>
                                            <td class="text-left visible-lg visible-md">{$v.name}</td>
                                            <td>
                                                {if condition='$v["authopen"] eq 1'}
                                                <a class="red" href="javascript:;" onclick="return tzyes({$v.id});" title="已开启">
                                                    <div id="yz{$v.id}">
                                                        <button class="btn btn-minier btn-danger">
                                                            无需验证
                                                        </button>
                                                    </div>
                                                </a>
                                                {else/}
                                                <a class="red" href="javascript:;" onclick="return tzyes({$v.id});" title="已禁用">
                                                    <div id="yz{$v.id}">
                                                        <button class="btn btn-minier btn-yellow">需要验证</button>
                                                    </div>
                                                </a>
                                                {/if}
                                            </td>
                                            <td>
                                                {if condition='$v["menustatus"] eq 1'}
                                                <a class="red" href="javascript:;" onclick="return stateyes({$v.id});" title="已开启">
                                                    <div id="zt{$v.id}">
                                                        <button class="btn btn-minier btn-yellow">显示状态</button>
                                                    </div>
                                                </a>
                                                {else/}
                                                <a class="red" href="javascript:;" onclick="return stateyes({$v.id});" title="已禁用">
                                                    <div id="zt{$v.id}">
                                                        <button class="btn btn-minier btn-danger">隐藏状态</button>
                                                    </div>
                                                </a>
                                                {/if}
                                            </td>
                                            <td><input name="{$v.id}" class="list_order" value=" {$v.sort}" size="10"/></td>

                                            <td>
                                                <div class="action-buttons">
                                                    <a class="green" href="{:url('ruleEdit',array('id'=>$v['id']))}" title="修改">
                                                        <i class="ace-icon fa fa-pencil bigger-130"></i>
                                                    </a>
                                                    <a class="red" href="javascript:;" onclick="return del({$v.id});" title="删除">
                                                        <i class="ace-icon fa fa-trash-o bigger-130"></i>
                                                    </a>
                                                </div>
                                            </td>
                                        </tr>
                                        {/volist}
                                        <tr>
                                            <td colspan="8" align="left">
                                                <button type="submit" id="btnorder" class="btn btn-white btn-yellow btn-sm">排序</button>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                                </form>
                            </div><!-- /.span -->
                        </div><!-- /.row -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div>
        </div>
    </div>
    {include file="common/foot" /}
</div>
<script>
    function del(id) {
        layer.confirm('你确定要删除吗？', {icon: 3}, function (index) {
            layer.close(index);
            window.location.href = "{:url('ruleDel')}?id=" + id + "";
        });
    }
    function stateyes(id) {
        $.post('{:url("ruleState")}', {id: id}, function (data) {
            if (data.status) {
                if (data.info == '状态禁止') {
                    var a = '<button class="btn btn-minier btn-danger">隐藏状态</button>'
                    $('#zt' + id).html(a);
                    return false;
                } else {
                    var b = '<button class="btn btn-minier btn-yellow">显示状态</button>'
                    $('#zt' + id).html(b);
                    return false;
                }
            }
        });
        return false;
    }


    function tzyes(id) {
        $.post('{:url("ruleTz")}', {id: id}, function (data) {
            if (data.status) {
                if (data.info == '无需验证') {
                    var a = '<button class="btn btn-minier btn-danger">无需验证</button>'
                    $('#yz' + id).html(a);
                    return false;
                } else {
                    var b = '<button class="btn btn-minier btn-yellow">需要验证</button>'
                    $('#yz' + id).html(b);
                    return false;
                }
            }
        });
        return false;
    }


    $('#ruleAdd').ajaxForm({
        beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
        success: complete, // 这是提交后的方法
        dataType: 'json'
    });

    function checkForm() {
        if ('' == $.trim($('#title').val())) {
            layer.alert('名称不能为空', {icon: 5}, function (index) {
                layer.close(index);
                $('#title').focus();
            });
            return false;
        }

        if ('' == $.trim($('#name').val())) {
            layer.alert('控制器/方法不能为空', {icon: 5}, function (index) {
                layer.close(index);
                $('#name').focus();
            });
            return false;
        }
    }

    function complete(data) {
        if (data.status == 1) {
            layer.alert(data.info, {icon: 6}, function (index) {
                layer.close(index);
                window.location.href = data.url;
            });
        } else {
            alert(data.info);
            return false;
        }
    }




    $(function () {
        $('#ruleorder').ajaxForm({
            success: complete, // 这是提交后的方法
            dataType: 'json'
        });


        function complete(data) {
            if (data.status == 1) {
                layer.alert(data.info, {icon: 6}, function (index) {
                    layer.close(index);
                    window.location.href = data.url;
                });
            } else {
                layer.alert(data.info, {icon: 6}, function (index) {
                    layer.close(index);
                    window.location.href = data.url;
                });
            }
        }
    });

</script>
</body>
</html>
